package providers

import (
	"bytes"
	"github.com/cihub/seelog"
	"html/template"
	"path/filepath"
)

var Logger seelog.LoggerInterface

func init() {

	var err error
	var logByte bytes.Buffer

	tmpl, err := template.ParseFiles(
		filepath.Join(RootPath, "config", "log.xml"),
	)
	if err != nil {
		panic("日志文件模版解析失败:" + err.Error())
	}

	_ = tmpl.Execute(
		&logByte,
		struct {
			RootPath string
		}{
			RootPath: RootPath,
		},
	)

	// 使用模版替换，匹配对应的路径
	// seelog.LoggerFromConfigAsFile()
	Logger, err = seelog.LoggerFromConfigAsBytes(logByte.Bytes())

	if err != nil {
		panic("日志读取配置文件失败:" + err.Error())
	}
}
